package com.grape.juc.thread.realize;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
/**
 * CallableMethod 
 *
 * @date: 2021/1/13 20:43
 * @author: myx 
 * @version: V0.1
 * Copyright: 2020 serve51. All rights reserved. 
 */
public class CallableMethod implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return "异步方法执行成功";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new CallableMethod());
        Thread thread = new Thread(futureTask);
        thread.start();
        String result = futureTask.get();
        System.out.println(Thread.currentThread().getName() + result);
    }
}